/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package api.user;

import Model.User.UserList;
import RssEasy.Core.Encrypt;
import RssEasy.Core.HttpRequestHelper;
import RssEasy.Core.ServletRequestHelper;
import RssEasy.Core.SignVerifyRequestHelper;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author admin
 */
@WebServlet(name = "api_login_amend", urlPatterns = {"/api/login/amend"})
public class amend extends ServletRequestHelper {

  @Override
    protected HttpRequestHelper request(HttpServletRequest request, HttpServletResponse response) {
        super.request(request, response);
        try {
            UserList list = new UserList(this.pageContext);
            UserList sel = new UserList(this.pageContext);
            String pwd =Encrypt.Md532(this.get("account") + this.get("pwd"));
            list.request();
            sel.request();
            if(!sel.select("myid").where("account='"+this.get("account")+"' and enterprise='"+this.get("enterprise")+"' and pwd='"+pwd+"'").get_first_rows()){
                throw new Exception("110");
            }
            list.remove("newpwd");
            list.keyvalue("pwd", Encrypt.Md532(this.get("account") + this.get("newpwd")));
            list.update().where("enterprise=? and account=?",this.get("enterprise"),this.get("account")).submit();
            out.print("{\"rsscode\":100}");
        } catch (Exception e) {
            out.print("{\"rsscode\":" + e.getMessage() + "}");
        }
        return this;
    }

}
